﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TooltracePC
{
    public partial class frmAdmin : Form
    {
        public frmAdmin()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string strOldPass = "";
            string strPass1 = "";
            string strPass2 = "";
            string PassWordMd5 = "";

            strOldPass = tbOrPass.Text.Trim();
            strPass1 = tbNewPass1.Text.Trim();
            strPass2 = tbNewPass2.Text.Trim();

            if (string.IsNullOrEmpty(strOldPass) || string.IsNullOrEmpty(strPass1) || string.IsNullOrEmpty(strPass2))
            {
                MessageBox.Show("不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if(strPass1 != strPass2)
            {
                MessageBox.Show("两次密码不一致", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            encode enMd5 = new encode();
            strOldPass = enMd5.strToMd5(strOldPass);
            strPass1 = enMd5.strToMd5(strPass1);

            dbAdmin dbAdmin1 = new dbAdmin();
            DataTable dtUser = dbAdmin1.getAdminByName("admin");

            PassWordMd5 = dtUser.Rows[0]["p"].ToString();
            if(PassWordMd5 != strOldPass)
            {
                MessageBox.Show("旧密码验证不通过!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            dbAdmin1.updatePass(strPass1, "admin");

            MessageBox.Show("密码更改成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Hand);

            this.Close();
        }
    }
}
